package com.etone.smartAudit.task;

import com.etone.smartAudit.service.FileUploadService;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author: 蒋学伟
 * @create: 2020-07-22 08:22:00
 * @Description 文件清理定时任务
 */
@Component
@Log4j2
public class FileTask {

    @Value("${audit.task.enable:false}")
    private Boolean enableTask;

    @Autowired
    private FileUploadService fileUploadService;

    /**
     * 定时清理一天前的图片,0到3点间，每半小时执行一次清理，每次清理最多1万条，一天清理最多6万条
     */
    @Scheduled(cron = "0 0/30 0-3 * * ?")
    public void clean() {
        if(enableTask){
            log.info("===========================开始清理垃圾图片===========================");
            fileUploadService.cleanFile();
            log.info("===========================清理垃圾图片结束===========================");
        }
    }
}
